﻿<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>添加文件配置</title>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link href="../lib/layui/css/layui.min.css" rel="stylesheet" />
    <link href="../x-admin/css/font.css" rel="stylesheet" />
    <link href="../x-admin/css/xadmin.css" rel="stylesheet" />
    <script type="text/javascript" src="../lib/Base64/base64.min.js"></script>
    <script type="text/javascript" src="../linq.js/linq.js"></script>
    <script src="../lib/cookie/cookie.js"></script>
</head>
<body>
    <div class="layui-card-body" style="">
        <form name="newProcessF" id="newProcessF" class="layui-form">
            <input type="text" name="dir" id="dir" value="" style="display:none" />
            <div class="layui-form-item">
                <label class="layui-form-label">数据源名称:</label>
                <div class="layui-input-block">
                    <select name="docName" id="docName" lay-filter="docName" style="float:left;height:35px;margin-bottom:15px;" lay-search="">
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">文 件 名:</label>
                <div class="layui-input-block">
                    <input type="text" name="filename" autocomplete="off" required="required" lay-verify="required" placeholder="(必填)请输入文件名" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">备注名称:</label>
                <div class="layui-input-block">
                    <input type="text" name="explain" autocomplete="off" placeholder="请输入备注名称" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button type="submit" class="layui-btn" lay-submit lay-filter="savefile">立即提交</button>
                </div>
            </div>
        </form>
    </div>
    <script src="../lib/layui/layui.js"></script>
    <script type="text/javascript">
        function getrequest() {
            var url = location.search; //获取url中"?"符后的字串
            var theRequest = new Object();
            if (url.indexOf("?") != -1) {
                var str = url.substr(1);
                strs = str.split("&");
                for (var i = 0; i < strs.length; i++) {
                    theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
                }
            }
            return theRequest;
        }
        var dir = getrequest().dir;
        layui.$.ajax({
            type: "get",
            url: localStorage.getItem('hosttingaddr') + "/Manager/ProcessCfgFile/addfile?dir=" + dir,
            headers: {
                user: getCookie("userinfo"),
                version: getCookie("version")
            },
            success: function (data) {
                $ = layui.$;
                $("#dir").val(dir);
                var htmlstr = "";
                data.forEach(function (o) {
                    htmlstr += "<option value=\"" + o.code + "\">" + o.code + "-" + o.name + "</option>";
                });
                $("#docName").html(htmlstr);
                //需要进行重新渲染
                layui.form.render('select');
            }
        });



        layui.use('form', function () {
            var form = layui.form;
            //监听提交
            form.on('submit(savefile)', function (data) {
                var formData = new FormData($("#newProcessF")[0]);
                $.ajax({
                    cache: false,
                    type: "post",
                    url: localStorage.getItem('hosttingaddr') + "/Manager/ProcessCfgFile/savefile",
                    headers: {
                        user: getCookie("userinfo"),
                        version: getCookie("version")
                    },
                    data: formData,
                    dataType: "JSON",
                    processData: false,
                    contentType: false,
                    async: false,
                    success: function (data) {
                        if (data == "success") {
                            alert("保存完成");
                            layer.msg('保存完成!', { icon: 1, time: 1000 });
                            window.parent.location.reload();
                            var index = parent.layer.getFrameIndex(window.name); //获取当前窗口的name
                            parent.layer.close(index);
                        } else {
                            layer.msg('发生错误:', { icon: 1, time: 1000 });
                        }
                    },
                    error: function (jqXHR, textStatus, errorThrown) {
                        if (jqXHR.responseText == "success") {
                            layer.msg('保存完成!', { icon: 1, time: 1000 });
                            window.parent.location.reload();
                            var index = parent.layer.getFrameIndex(window.name); //获取当前窗口的name
                            parent.layer.close(index);
                        } else {
                            layer.msg('发生错误:' + jqXHR.responseText, { icon: 1, time: 1000 });
                        }
                    }
                });
                return false;
            });
        });


    </script>
</body>
</html>